home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9734 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Standard question - pointer initialization
  5. Date: 13 Mar 1996 00:40:26 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4i55hq$sc1@sparcserver.lrz-muenchen.de>
  9. References: <4hk9un$906@hammer.msfc.nasa.gov> <4i52bk$5el@s02.pavilion.co.uk>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. AJRobb@pavilion.co.uk (Andy J Robb) writes:
  13.  
  14. >Brian.Day@msfc.nasa.gov (Brian Day) wrote:
  15.  
  16. >>Doesn't the standard say something about some pointers
  17. >>being automatically initialized to NULL, or something like that?
  18.  
  19. >Off the top of my head, the only time pointers are initialized to NULL
  20. >is if they are global or static.
  21.  
  22. >The use of calloc() allows a list of NULL initialized pointers to be
  23. >generated.
  24.  
  25. Yes it does:
  26.  
  27.    int i;
  28.    foo *p = calloc(N, sizeof *p);
  29.    if (p)
  30.       for (i = 0; i < N; i++)
  31.          p[i] = NULL;
  32.  
  33. However, this statement is somehow misleading because it could
  34. be understood to mean something like "if you allocate a vector
  35. of pointers with calloc(), all pointers will be initialized
  36. to NULL", which is not true. A NULL pointer need not have all
  37. bits set to zero, and this is what calloc() does with the memory
  38. it allocates.
  39.  
  40. Kurt
  41. --
  42. | Kurt Watzka                             Phone : +49-89-2180-6254
  43. | watzka@stat.uni-muenchen.de
  44. | ua302aa@sunmail.lrz-muenchen.de
  45.  
  46.